<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

<div id="bedtoolbar" style="padding: 10px">
	<a href="javascript:void(0)" class="easyui-linkbutton"
		iconCls="icon-add" onclick="newUserBed()">增加病床</a>
	<a href="javascript:void(0)" class="easyui-linkbutton"
		iconCls="icon-add" onclick="editUserBed()">入院</a> <a
		href="javascript:void(0)" class="easyui-linkbutton"
		iconCls="icon-edit" onclick="editUserBed()">修改</a> <a
		href="javascript:void(0)" class="easyui-linkbutton"
		iconCls="icon-remove" onclick="outUserBed()">出院</a> <a
		href="javascript:void(0)" class="easyui-linkbutton"
		iconCls="icon-tip" onclick="showUserBed()">查看</a>
</div>
<div id="contenInfo" style="min-height: 540px;">
<table>
	<tr>
		<c:forEach var="bed" items="${bedList }" varStatus="ind">
		<td>
			<div class="easyui-panel" style="width:248px">
			<table style="padding:5px;width:100%">
				<tr>
					<td width="30%" align="right">当前体温：</td>
					<td>
						<c:choose>
							<c:when test="${bed.patient.startTime==null||bed.tiwen==null }">
								<span style="font-size: 32px;"><strong>0.00℃</strong></span>
							</c:when>
							<c:when test="${bed.tiwen.measureNumOne>=38.5 }">
								<span style="font-size: 32px;color: red">
									<strong>${bed.tiwen.measureNumOne }℃</strong>
								</span>
							</c:when>
							<c:when test="${bed.tiwen.measureNumOne<38.5&&bed.tiwen.measureNumOne>37 }">
								<span style="font-size: 32px;color: orange">
									<strong>${bed.tiwen.measureNumOne }℃</strong>
								</span>
							</c:when>
							<c:otherwise>
								<span style="font-size: 32px;color: green">
									<strong>${bed.tiwen.measureNumOne }℃</strong>
								</span>
							</c:otherwise>
						</c:choose>
				</tr>
				<tr>
					<td align="right">病人名称：</td>
					<td>${bed.patient.name }</td>
				</tr>
				<tr>
					<td align="right">性别：</td>
					<td>${bed.patient.sex }</td>
				</tr>
				<tr>
					<td align="right">年龄：</td>
					<td>${bed.patient.age }</td>
				</tr>
				<tr>
					<td align="right">主治医师：</td>
					<td>${bed.patient.doctor }</td>
				</tr>
				<tr>
					<td align="right">值班护士：</td>
					<td>${bed.patient.nurse }</td>
				</tr>
				<tr>
					<td align="right">入院时间：</td>
					<td>${bed.patient.startTime }</td>
				</tr>
				<tr>
					<td align="right">床位状态：</td>
					<td>
					<c:choose>
						<c:when test="${bed.patient.startTime==null }">
							空闲
						</c:when>
						<c:otherwise>
							使用中
						</c:otherwise>
					</c:choose>
					</td>
				</tr>
				<tr>
					<td colspan="2" align="center">
						<hr/>
					</td>
				</tr>
				<tr>
					<td colspan="2" align="center">
						床号：${bed.name }<input type="checkbox" name="bedInfo" value="${bed.id }"/>
					</td>
				</tr>
			</table>
			</div>
		</td>
		<c:if test="${ind.count%5==0 }">
			</tr>
			<tr>
		</c:if>
	</c:forEach>
	<c:if test="${5-fn:length(bedList)%5>0 }">
		<td colspan="${5-fn:length(bedList)%5 }">&nbsp;</td>
	</c:if>
	</tr>
</table>
</div>
<div id="beddlg" title="设置" class="easyui-dialog"
	style="width: 400px; min-height: 280px; padding: 10px 20px"
	closed="true" buttons="#beddlg-buttons"></div>
<div id="beddlg-buttons">
	<a href="javascript:void(0)" class="easyui-linkbutton c6"
		iconCls="icon-ok" onclick="saveUserBed()" style="width: 90px">保存</a> <a
		href="javascript:void(0)" class="easyui-linkbutton"
		iconCls="icon-cancel"
		onclick="javascript:$('#beddlg').dialog('close')" style="width: 90px">取消</a>
</div>
<div class="easyui-panel">
	<div id="bed-pagination" class="easyui-pagination"></div>
</div>
<script type="text/javascript">
$(function(){
	$('#bed-pagination').pagination({
		total:${totalCount},
		pageNumber:${page},
		pageSize:${rows},
		onSelectPage:function(pageNumber, pageSize){
			reloadBedPage(pageNumber,pageSize);
		}
	});
});

function newUserBed(){
   	$.post('bed/edit.action',{'type':'edit'},function(data,statu){
		$("#beddlg").html(data);
		$.parser.parse("#beddlg");
		$('#beddlg').dialog('open');
	});
    url = 'bed/save.action';
}

function editUserBed(){
  	var checkNum=0;
   	var rowId;
   	$("input[type=checkbox][name=bedInfo]").each(function(){
   		if($(this).is(':checked')==true){
   			checkNum++;
   			rowId=$(this).val();
   		}
   	});
   	if(checkNum>1){
   		$.messager.alert('提示','一次只能编辑一条!');
   	}
   	else if(checkNum==0){
   		$.messager.alert('提示','请选择要操作的记录');
   	}
   	else{
   		$.post('bed/edit.action',{'type':'patient','id':rowId},function(data,statu){
			$("#beddlg").html(data);
			$.parser.parse("#beddlg");
			$('#beddlg').dialog('open');
		});
	    url = 'bed/update.action';
	}
}

function saveUserBed(){
	$('#bedfm').form('submit',{
        url: url,
        onSubmit: function(){
	        return $(this).form('validate');
        },
        success: function(result){
	        var result = eval('('+result+')');
	        if (result.errorMsg){
		        $.messager.show({
			        title: 'Error',
			        msg: result.errorMsg
		        });
	        } else {
		        $('#beddlg').dialog('close'); // close the dialog
		        reloadBedPage(${page},${rows});
	        }
        }
	});
}

function outUserBed(){
	var checkNum=0;
   	var rowId;
   	$("input[type=checkbox][name=bedInfo]").each(function(){
   		if($(this).is(':checked')==true){
   			checkNum++;
   			rowId=$(this).val();
   		}
   	});
   	if(checkNum<1){
   		$.messager.alert('提示','请选择要操作的床位信息!');
   	}
   	else{
   		$.post('bed/outBed.action',{'ids':rowId},function(data,statu){
   			$.messager.alert('提示','床位已空闲!');
   			reloadBedPage(${page},${rows});
		});
	}
}
function showUserBed(){
	var checkNum=0;
   	var rowId;
   	$("input[type=checkbox][name=bedInfo]").each(function(){
   		if($(this).is(':checked')==true){
   			checkNum++;
   			rowId=$(this).val();
   		}
   	});
   	if(checkNum>1){
   		$.messager.alert('提示','一次只能查看一条!');
   	}
   	else if(checkNum==0){
   		$.messager.alert('提示','请选择要操作的记录');
   	}
   	else{
   		$.post('bed/show.action',{'id':rowId},function(data,statu){
   			if(statu=='success'){
   				var title=data.data.name;
	        	 if ($('#tt').tabs('exists', title)){
	        		 $('#tt').tabs('select', title);
       		 	} else {
       		 		if(data.data.equipNo){
       		 			var url="show/index.action?equipNo="+data.data.equipNo+"&id="+data.data.id;
						var content = '<iframe scrolling="auto" frameborder="0"  src="'+url+'" style="width:100%;height:100%;"></iframe>';
	        			$('#tt').tabs('add',{
	        				title:title,
	        				content:content,
	        				closable:true
	        			});
       		 		}
       		 		else{
       		 			$.messager.alert("提示","未找到对应的记录！")
       		 		}
	        	}
   			}
   		});
   	}
}
</script>